try:
    print('haha')
    int('afa')
except Exception as e:
    print(f'异常了{e}')
else:
    print('else.没有异常时执行')
finally:
    print("无论是否异常都要执行的代码")

try:
    print(num)
except (NameError, ZeroDivisionError) as result:
    print(result)


# 自定义异常
class MyError(Exception):
    def __str__(self):
        return '自定义异常'


try:
    raise MyError()
except (Exception) as e:
    print(e)
